package cn.wolfcode.service.impl;

import cn.wolfcode.domain.MessageReply;
import cn.wolfcode.mapper.MessageReplyMapper;
import cn.wolfcode.qo.MessageReplyQueryObject;
import cn.wolfcode.service.IMessageReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class MessageReplyServiceImpl implements IMessageReplyService {

    @Autowired
    private MessageReplyMapper messageReplyMapper;



    @Override
    @Transactional
    public void save(MessageReply messageReply) {

        //创建时间
        messageReply.setCreateTime(new Date());
        messageReplyMapper.insert(messageReply);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        messageReplyMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(MessageReply messageReply) {
        messageReplyMapper.updateByPrimaryKey(messageReply);
    }

    @Override
    public MessageReply get(Long id) {
        return messageReplyMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MessageReply> listAll() {
        return messageReplyMapper.selectAll();
    }

    @Override
    public PageInfo<MessageReply> query(MessageReplyQueryObject qo) {
        // 告诉插件我们查询的是第几页，每页多少条
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        // 查询当前页的数据
        List<MessageReply> messageReplys = messageReplyMapper.selectForList(qo);
        return new PageInfo<>(messageReplys);
    }
}
